package com.zyy.game.tianlong.vo;

import com.zyy.game.tianlong.entity.Player;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.*;
import java.util.Date;

/**
 * 传给客户端的玩家信息对象
 *
 * @author relufi
 * @date 2019/8/14 0014
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PlayerInfo {
    /**
     * 玩家ID
     */
    private int playerId;

    /**
     * 玩家名称
     */
    private String playerName;

    /**
     * 玩家金币
     */
    private long coins;

    /**
     * 玩家豆
     */
    private long bean;

    /**
     * 是否是微信登录
     */
    private boolean wxLogin;

    /**
     * 头像
     */
    private String photo;

    /**
     * 是否设置了支付密码
     */
    private boolean payPassWord;

    /**
     * 第连续签到次数
     */
    private int signCount;

    /**
     * 个性签名
     */
    private String signature;

    /**
     * 今天有没有签到
     */
    private boolean nowSign;

    public static PlayerInfo convertPlayer(Player player) {
        int signCount = player.getSignCount();
        Date signDate = player.getSignDate();
        boolean nowSign = false;
        if (signCount != 0 && signDate != null) {
            Instant instant = signDate.toInstant();
            LocalDate now = LocalDate.now();
            if (instant.isBefore(LocalDateTime.of(now.minusDays(1), LocalTime.MIN).toInstant(ZoneOffset.ofHours(8)))) {
                signCount = 0;
            } else if (instant.equals(LocalDateTime.of(now, LocalTime.MIN).toInstant(ZoneOffset.ofHours(8)))) {
                nowSign = true;
            }
        }
        return new PlayerInfo(player.getPlayerId(), player.getPlayerName(), player.getCoins(), player.getBean(), player.getOpenId() != null, player.getPhoto(), player.getPayPassword() != null, signCount, player.getSignature(), nowSign);
    }
}
